<template>
  <el-table border :data="data" style="width: 100%" :height="height">
    <el-table-column prop="xm" label="姓名" />
    <el-table-column prop="jh" label="警号" />
    <el-table-column prop="sfzmhm" label="身份证号" />
    <el-table-column prop="mz" label="民族" />
    <el-table-column prop="bmmc" label="部门" />
    <el-table-column prop="ryzt" label="用户状态" />
    <el-table-column prop="ryxh" label="人员序号" />  
    <!-- <el-table-column label="操作">
      <template #default="scope">
        <el-button type="text" size="small" @click="handleView(scope.row)"
          >查看</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="handleModify(scope.row)"
          v-if="userRole === 'admin'"
          >修改</el-button
        >
      </template>
    </el-table-column> -->
  </el-table>

  <!-- <AuthorityManagements
    :page-list="pageList"
    :user-role="userRole"
    ref="AuthorityManagementS"
    @confirm="handleAuthorityConfirm"
  /> -->
</template>

<script setup>
import AuthorityManagements from "@/components/AuthorityManagements/index.vue";
import * as MapApi from "@/service/api/map";
const AuthorityManagementS = ref();
const checkedPages = ref([]);
const pageList = ref([]);
const params = ref({
  pageNum: 1,
  pageSize: 1,
  xm: "", //姓名
});

const props = defineProps({
  data: {
    type: Array
  },
  height: {
    type: Number,
    default: 500,
  },
  userRole: {
    type: String,
    default: "police",
  },
  pageLists: {
    type: Array,
    default: () => [],
  },
});

const userRole = ref(props.userRole);

const setUserRole = (role) => {
  userRole.value = role;
};

const selectedRow = ref(null);
const showAuthorityDialog = ref(false);
const actionType = ref(""); // 'view'或'modify'

const handleRowClick = (row) => {
  selectedRow.value = row;
};

const handleCheckedPagesUpdate = (newChecked) => {
  checkedPages.value = newChecked;
};

const handleAuthorityConfirm = (selectedPages) => {
  checkedPages.value = selectedPages;
  // 更新当前行的页面权限配置
  if (selectedRow.value) {
    selectedRow.value.pageList.forEach((p) => {
      p.disabled = !selectedPages.includes(p.path);
    });
  }
};

const handleView = (row) => {
  pageList.value = row.pageList;
  selectedRow.value = row;
  actionType.value = "view";
  userRole.value = "police";
  AuthorityManagementS.value.showAuthorityDialog = true;
};
const handleModify = (row) => {
  pageList.value = row.pageList;
  selectedRow.value = row;
  if (userRole.value === "admin") {
    actionType.value = "modify";
    AuthorityManagementS.value.showAuthorityDialog = true;
  }
};
</script>

<style lang="less" scoped></style>
